import { getCompanyID, getPosIDs, getTenantID, getUserDepID, getUserID, requestFunComponFiex } from '@/utils';
import { useRequest } from 'umi';
import { getBaseUrl } from '@/services/urlconst';
import { ILoadMapTypeAll } from '@/common';

const baseUrl = getBaseUrl();

/**
 * 审核接口
 * */
export const AuditPlanMaterialServices = (callback: (res: any) => void) => {
  const request = useRequest(
    (payload) => {
      let bodyParams = {
        ...payload,
        checkerID: getUserID(),
        checkPositionID: getPosIDs(),
        checkDepartmentID: getUserDepID(),
        checkCompanyID: getCompanyID(),
      };
      let reqUrl = `${baseUrl}/purchaseNeedMaterialController/check`;
      return requestFunComponFiex('PUT', reqUrl, bodyParams);
    },
    {
      manual: true,
      onSuccess: callback,
    },
  );

  return {
    auditPlanRun: request?.run,
    auditPlanLoading: request?.loading,
  };
};

/**
 * 获取计划详情接口
 * */
export const detailPlanServices = (callback: (res: any) => void) => {
  const request = useRequest(
    (payload) => {
      let bodyParams = {
        ...payload,
        dicTypeIds: `${getTenantID()}${ILoadMapTypeAll.PURCHASE_CATEGORY},${getTenantID()}${ILoadMapTypeAll.MATERIAL_MIDI},10013403`,
      };
      let reqUrl = `${baseUrl}/purchasePlanController/getPlanDetails`;

      return requestFunComponFiex('POST', reqUrl, bodyParams); //bodyParams
    },
    {
      // manual: true,
      onSuccess: callback,
    },
  );

  return {
    detailPlanRun: request?.run,
    detailPlanLoading: request?.loading,
  };
};

/**
 * 校验物料列表是否审核通过--【此接口修改状态为复核完成】
 * */
export const auditCompletionServices = (callback: (res: any) => void) => {
  const request = useRequest(() => {}, {
    manual: true,
    onSuccess: callback,
  });

  return {
    auditCompletionRun: request?.run,
    auditCompletionLoading: request?.loading,
  };
};
